Skip to content

Conversation

TimG1964
Copy link
Contributor

This PR fixes the issue reported in #43. I've added extra tests, too.

One caveat in testing: I had to change one test (only):

    @testset "next and prev" begin
        @test XML.prev(doc[1]) === data

I had to change the condition from === to only ==. With this single change, tests now all pass locally.

I've also checked that this PR works well with XLSX.jl downstream and all XLSX tests also pass locally.

With this PR, XLSX now properly reads a workbook like this:
image
which has leading and trailing whitespace in column A and, in column B, only has whitespace.
Reading this XLSX file now works correctly:

julia> f=XLSX.openxlsx(raw"C:\Users\tim\OneDrive\Documents\Julia\XLSX\sstTest.xlsx", mode="rw")
XLSXFile("sstTest.xlsx") containing 1 Worksheet
            sheetname size          range        
-------------------------------------------------
               Sheet1 5x2           A1:B5        

julia> f[1][:]
5×2 Matrix{Any}:
 "  hello"    "    "
 "  hello  "  "    "
 " hello\">"  "    "
 "hello\">"   "    "
 "  hello"    "    "

Previously, leading and trailing spaces would be trimmed, and cells containing only whitespace would become missing.

I'm afraid I can't match the simple elegance of your coding style, though!

@TimG1964
Copy link
Contributor Author

Hi Josh. Is there a reason you haven't merged this? Let me know if there is anything more I need to do or if it doesn't pass muster for some reason. Thx.

@joshday
Copy link
Member

joshday commented Jul 29, 2025

Sorry for not responding!

I was in the middle of rewriting a bit of the XML internals when you made the PR and then both the rewrite and this PR got pushed to the back burner by other work.

LGTM, and again my apologies for the delay!

@joshday joshday merged commit 120038d into JuliaComputing:main Jul 29, 2025
16 checks passed
@TimG1964
Copy link
Contributor Author

Thank you! Will there be a new release?

@TimG1964 TimG1964 deleted the Preserve-whitespace branch July 29, 2025 21:37
@joshday
Copy link
Member

joshday commented Jul 29, 2025

Yes!

JuliaRegistries/General#135609

TimG1964 added a commit to TimG1964/XML.jl that referenced this pull request Aug 14, 2025
joshday pushed a commit that referenced this pull request Sep 2, 2025
* Address speed regression in #46 and fix reamining
issues in #45.

* Use @views more often for slices

* undo skip orphan text nodes (cf. EzXML)
joshday pushed a commit that referenced this pull request Sep 4, 2025
* Address speed regression in #46 and fix reamining
issues in #45.

* Use @views more often for slices

* undo skip orphan text nodes (cf. EzXML)

* Amend `XML.write` to honour `xml:space="preserve"`

* Update write to respect xml:space

* Correct isspace test

* Fix isspace

* more isspace

* Normalize_newlines

* Normalize_newlines

* Undo normalize newlines

* Undo normalize newlines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants